import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {longLimtVal, longLimtValAndNotBlank, rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {list} from "@/views/baseinfo/person/SsPerson.api";
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '姓名',
    align:"center",
    dataIndex: 'wbname'
   },
   {
    title: '证件类型',
    align:"center",
    dataIndex: 'wbpaperType_dictText'
   },
   {
    title: '证件号码',
    align:"center",
    dataIndex: 'wbpaperNumber'
   },
   {
    title: '手机号码',
    align:"center",
    dataIndex: 'wbphone'
   },
   {
    title: '预约来访时间',
    align:"center",
    sorter: true,
    dataIndex: 'willVisitTime'
   },
  {
    title: '预约截止时间',
    align:"center",
    sorter: true,
    dataIndex: 'willVisitEndTime'
  },
   {
    title: '受访人',
    align:"center",
    dataIndex: 'meetPersonId_dictText'
   },
   {
    title: '来访说明',
    align:"center",
    dataIndex: 'visitDescription'
   },
  {
    title: '是否允许',
    align:"center",
    dataIndex: 'allow_dictText'
  },
  {
    title: '预约途径',
    align:"center",
    dataIndex: 'source_dictText'
  }

];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "姓名",
      field: 'name',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "证件号码",
      field: 'paperNumber',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "手机号码",
      field: 'phone',
      component: 'Input',
      //colProps: {span: 6},
 	},
     {
      label: "预约来访时间",
      field: "willVisitTime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'wbname',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          required:true,
          validator: (_, value) => {
            return longLimtValAndNotBlank(value,10)
          },
        },
      ];
    },
  },
  {
    label: '证件类型',
    field: 'wbpaperType',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"paperType",
      stringToNumber:true,
    },
    defaultValue:0,
  },
  {
    label: '证件号码',
    field: 'wbpaperNumber',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          required:true,
          validator: (_, value) => {
            return longLimtVal(value,20)
          },
        },
      ];
    },
  },
  {
    label: '手机号码',
    field: 'wbphone',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,20)
          },
        },
      ];
    },
  },
  {
    label: '来访人数',
    field: 'wbcount',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,3)
          },
        },
      ];
    },
  },
  {
    label: '车牌号',
    field: 'wbplate',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,20)
          },
        },
      ];
    },
  },
  {
    label: '预约来访时间',
    field: 'willVisitTime',
    component: 'DatePicker',
    componentProps: {
       showTime: true,
       valueFormat: 'YYYY-MM-DD HH:mm:ss'
     },
    dynamicRules: ({model,schema}) => {
      return [
        {required:true,
          message:"预约来访时间不能来空",
        },
      ];
    },
  },
  {
    label: '预约截止时间',
    field: 'willVisitEndTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        {required:true,
          message:"预约截止时间不能来空",
        },
      ];
    },
  },
  {
    label:"预约途径",
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"visit_appointment_source",
      stringToNumber:true,
    },
    field:"source",
    defaultValue:1,
   // show:false,
  },
  {
    label: '受访人',
    field: 'meetPersonId',
    component: 'JSearchSelect',
    componentProps: ({ formModel, formActionType }) => {  //formModel, formActionType
      console.log('formModel:', formModel);
      return {
        dict:"ss_person where status != 0,name,id",
        pageSize: 5,
        async: true,
        onChange: (e: any) => {
          console.log(e);
          console.log(formActionType);
          console.log(formModel);
          if(!e){
            formModel.personName = "";
            formModel.personCode = "";
            formModel.personDept = "";
            formModel.personType = "";
            return;
          }
          let params = {id:e};
          console.log(params);
          let res =  list(params);
          res.then((data)=>{
            console.log(data);
            if(data.records?.length>0){
              formModel.personName = data.records[0].name;
              formModel.personCode = data.records[0].code;
              formModel.personDept = data.records[0].departmentId_dictText;
              formModel.personType = data.records[0].personType;
            }
          })
        },
      };
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入选择人员!'},
      ];
    },
  },
  {
    label:"受访人姓名",
    component:"Input",
    field:"personName",
    dynamicDisabled:true,
  },
  {
    label:"受访人学/工号",
    component:"Input",
    field:"personCode",
    dynamicDisabled:true,
  },
  {
    label:"受访人所属部门",
    component:"Input",
    field:"personDept",
    dynamicDisabled:true,
  },
  {
    label:"受访人人员类型",
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"personType",
    },
    field:"personType",
    dynamicDisabled:true,
  },
  {
    label: '来访说明',
    field: 'visitDescription',
    component: 'InputTextArea',
  },
  {
    label:"是否允许",
    field:"allow",
    component:"JDictSelectTag",
    componentProps: {
      dictCode:"visit_appointment_allow",
      stringToNumber:true,
    },
    defaultValue:0,
  },
  {
    label: '审批备注',
    field: 'remark',
    component: 'InputTextArea',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '姓名',order: 0,view: 'text', type: 'string',},
  paperType: {title: '证件类型',order: 1,view: 'number', type: 'number',},
  paperNumber: {title: '证件号码',order: 2,view: 'text', type: 'string',},
  phone: {title: '手机号码',order: 3,view: 'text', type: 'string',},
  willVisitTime: {title: '预约来访时间',order: 4,view: 'datetime', type: 'string',},
  meetPersonId: {title: '受访人',order: 5,view: 'text', type: 'string',},
  visitDescription: {title: '来访说明',order: 6,view: 'text', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
